CC		= gcc
CFLAGS		= -O2 -Wall -Wextra -march=native -mtune=native
DBGFLAGS	= -Wall -Wextra -O0 -g3
LDFLAGS 	= -I/usr/local/include -L/usr/local/lib -lmp3lame -lasound -lvorbisfile -lm -logg -lfaad -lvorbis -lFLAC -ldl
GTKFLAGS	= `pkg-config --cflags --libs gtk+-2.0`
PROGNAME	= soundplayer
LIB_DIR 	= ./lib
INSTALL 	= /usr/bin/install -c
BINDIR		= ~/bin
BUILD_DIR	= ./build

all: soundplayer sounddaemon gsoundplayer #libspfilter

default: soundplayer

soundplayer: out
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$(PROGNAME) $(LIB_DIR)/*.c src/$(PROGNAME).c $(LDFLAGS)

sounddaemon: out
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/sounddaemon $(LIB_DIR)/*.c src/sounddaemon.c $(LDFLAGS)

gsoundplayer: out
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/gsoundplayer $(LIB_DIR)/*.c src/gsoundplayer.c $(LDFLAGS) $(GTKFLAGS)
	
libspfilter: out soundplayer
	$(CC) -fPIC -shared -Wl,-soname,libspfilter.so,-export-dynamic -o $(BUILD_DIR)/libspfilter.so $(LIB_DIR)/filters/soundplayer_filters.c # library_list

debug: out
	$(CC) $(DBGFLAGS) -o $(BUILD_DIR)/$(PROGNAME) $(LIB_DIR)/*.c src/$(PROGNAME).c $(LDFLAGS)
	$(CC) $(DBGFLAGS) -o $(BUILD_DIR)/sounddaemon $(LIB_DIR)/*.c src/sounddaemon.c $(LDFLAGS)
	$(CC) $(DBGFLAGS) -o $(BUILD_DIR)/gsoundplayer $(LIB_DIR)/*.c src/gsoundplayer.c $(LDFLAGS) $(GTKFLAGS)
	$(CC) -fPIC -shared -Wl,-soname,libspfilter.so,-export-dynamic -o $(BUILD_DIR)/libspfilter.so $(LIB_DIR)/filters/soundplayer_filters.c # library_list
	
out:
	mkdir -p $(BUILD_DIR)

install:
	$(INSTALL) -m 755 $(BUILD_DIR)/$(PROGNAME) $(BINDIR)
	$(INSTALL) -m 755 $(BUILD_DIR)/sounddaemon $(BINDIR)
	$(INSTALL) -m 755 $(BUILD_DIR)/gsoundplayer $(BINDIR)
	$(INSTALL) -m 655 $(BUILD_DIR)/libspfilter.so $(BINDIR)

clean:
	rm -rvf ./build
	rm -vf */*.a
	rm -vf */*.o

depend:
	aptitude install libflac-dev libfaad-dev libmp3lame-dev libasound-dev libgtk2.0-dev libvorbis-dev
